<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>truncate</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="language.modifiers.html" title="Chapter 5. Variable Modifiers">
<link rel="prev" href="language.modifier.to_charset.html" title="to_charset">
<link rel="next" href="language.modifier.unescape.html" title="unescape">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">truncate</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="language.modifier.to_charset.html">Prev</a> </td>
<th width="60%" align="center">Chapter 5. Variable Modifiers</th>
<td width="20%" align="right"> <a accesskey="n" href="language.modifier.unescape.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="truncate">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="language.modifier.truncate"></a>truncate</h2></div></div></div>
<p>
     This truncates a variable to a character length, the default is 80.
     As an optional second parameter, you can specify a string of text
     to display at the end if the variable was truncated. The
     characters in the string are included with the original truncation length.
     By default, <code class="varname">truncate</code> will attempt to cut off at a
     word boundary. If you want to cut off at the exact character length,
     pass the optional third parameter of <code class="constant">TRUE</code>.
  </p>
<div class="informaltable"><table border="1">
<colgroup>
<col align="center">
<col align="center">
<col align="center">
<col align="center">
<col>
</colgroup>
<thead><tr>
<th align="center">Parameter Position</th>
<th align="center">Type</th>
<th align="center">Required</th>
<th align="center">Default</th>
<th>Description</th>
</tr></thead>
<tbody>
<tr>
<td align="center">1</td>
<td align="center">integer</td>
<td align="center">No</td>
<td align="center">80</td>
<td>This determines how many characters to truncate
       to.</td>
</tr>
<tr>
<td align="center">2</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center">...</td>
<td>This is a text string that replaces the truncated text. Its length
      is included in the truncation length setting.</td>
</tr>
<tr>
<td align="center">3</td>
<td align="center">boolean</td>
<td align="center">No</td>
<td align="center"><code class="constant">FALSE</code></td>
<td>This determines whether or not to truncate at a
       word boundary with <code class="constant">FALSE</code>, or at the exact character with <code class="constant">TRUE</code>.</td>
</tr>
<tr>
<td align="center">4</td>
<td align="center">boolean</td>
<td align="center">No</td>
<td align="center"><code class="constant">FALSE</code></td>
<td>This determines whether the truncation happens at the end of the
      string with <code class="constant">FALSE</code>, or in the middle of the string with <code class="constant">TRUE</code>.
      Note that if this setting is <code class="constant">TRUE</code>, then word boundaries are ignored.
      </td>
</tr>
</tbody>
</table></div>
<div class="example">
<a name="id357271"></a><p class="title"><b>Example 5.21. truncate</b></p>
<div class="example-contents">
<pre class="programlisting">

&lt;?php
$smarty-&gt;assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
?&gt;

   </pre>
<p>
    where template is:
   </p>
<pre class="programlisting">

{$articleTitle}
{$articleTitle|truncate}
{$articleTitle|truncate:30}
{$articleTitle|truncate:30:""}
{$articleTitle|truncate:30:"---"}
{$articleTitle|truncate:30:"":true}
{$articleTitle|truncate:30:"...":true}
{$articleTitle|truncate:30:'..':true:true}

   </pre>
<p>
    This will output:
   </p>
<pre class="screen">

Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after...
Two Sisters Reunite after
Two Sisters Reunite after---
Two Sisters Reunite after Eigh
Two Sisters Reunite after E...
Two Sisters Re..ckout Counter.

   </pre>
</div>
</div>
<br class="example-break">
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="language.modifier.to_charset.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="language.modifiers.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="language.modifier.unescape.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">to_charset </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> unescape</td>
</tr>
</table>
</div>
</body>
</html>
